#! -*- Encoding: Latin-1 -*-

## This is the main integration script. By defining Python functions here, you make them available
## for C++ code to call. 

import builtin
import sys
import os
import dumpmods
import threading

def test_function_with_parameters(a,b):
    return a*b

def python_thread_proc(n, i):
    ct = repr(threading.currentThread())
    for k in range(20):
        builtin.inc("+%s.%s.%d.%s" % (n, i, k, ct, ))
        
    for k in range(20):
        builtin.dec("-%s.%s.%d.%s" % (n, i, k, ct, ))
        

def test_python_threading(n):
    print("test_python_threading(%d) called" % (n, ))
    
    def create_thread(i):
        return threading.Thread( target = python_thread_proc, args = (n, i, ) )
    
    # create all threads
    threads = [create_thread(i) for i in range(n)]
    
    # start all threads
    for thread in threads:
        thread.start()
        
    print "all python threads should now be running..."
    
    for thread in threads:
        thread.join()
        print "%r has ended" % (thread, )

    print "all threads have terminated"

print "loaded builtin module: %r" % (builtin.__VERSION__, )
print "this version exports a couple of threading tests."
print dir(builtin)

builtin.PyTrace("yeah for builtin")

generate_archive = dumpmods.generate_archive
